import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
import { SetUserInfo, SetToken, RemoveUserInfo, RemoveToken } from '@/untils/auth.js'

const store = new Vuex.Store({
	state: {
		token: uni.getStorageSync('token') || '',
		userInfo: uni.getStorageSync('userInfo') || '{}'
	},
	mutations: {
		// 存储userInfo
		UpdateUserInfo(state, newUser) {
			state.userInfo = newUser
			// 存储本地
			SetUserInfo(newUser)
		},
		// 删除
		RemoUserInfo(state) {
			state.userInfo = '{}'
			RemoveUserInfo()
		},
		// 存储token
		UpdateToken(state, newToken) {
			state.token = newToken
			SetToken(newToken)
		},
		RemoToken(state) {
			state.token = ''
			RemoveToken()
		}


	},
	modules: {}
})

export default store
